class Solution(object):
    def removeNthFromEnd(self, head, n):
        """
        :type head: ListNode
        :type n: int
        :rtype: ListNode
        """
        run = head
        tail = head
        while n>0:
            n -= 1
            tail = tail.next
        if not tail:
            run = head.next
            head.next = None
            return run
        while tail.next:
            run = run.next
            tail = tail.next
        tail = run.next.next
        run.next = tail
        return head